package com.yl.users.entity

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.yl.common.annotation.NoArg
import com.yl.users.pojo.dto.CompanyPermissionsViewDto
import java.util.*

@NoArg
@TableName("company_permissions_view")
class CompanyPermissionsView(
	/**
	 * 公司所属菜单内容
	 */
	@TableId(value = "id", type = IdType.AUTO)
	var id: Long,

	/**
	 * 菜单id
	 */
	@TableField("permissions_id")
	var permissionsId: Long? = null,

	/**
	 * 权限系统标识
	 */
	@TableField(exist = false)
	var perms: String? = null,

	/**
	 * 父级菜单id
	 */
	@TableField("parent_id")
	var parentId: Long? = null,

	/**
	 * 系统那边的父级id
	 */
	@TableField(exist = false)
	var sysPermParentId: Long ?= null,

	/**
	 * 菜单名称
	 */
	@TableField("permissions_name")
	var permissionsName: String,

	/**
	 * 排序
	 */
	@TableField("order_num")
	var orderNum: Int? = null,
	/**
	 * 菜单状态（1，显示，2隐藏）
	 */
	@TableField("visible")
	var visible: Int? = null,


	/**
	 * 图标
	 */
	@TableField("icon")
	var icon: String? = null,

	/**
	 * 创建用户
	 */
	@TableField("create_user_id")
	var createUserId: Long? = null,

	/**
	 * 创建时间
	 */
	@TableField("create_time")
	var createTime: Date? = null,

	/**
	 * 修改用户
	 */
	@TableField("update_user_id")
	var updateUserId: Long? = null,

	/**
	 * 修改时间
	 */
	@TableField("update_time")
	var updateTime: Date? = null,

	/**
	 * 数据有效性
	 */
	@TableField("enabled")
	var enabled: Int? = 1,

	/**
	 * 所属医院
	 */
	@TableField("company_id")
	var companyId: Long,

	/**
	 * 创建类型
	 */
	@TableField("create_type")
	var createType: Int? = null,

	@TableField("permissions_type")
	var permissionsType: Int? = null,

	@TableField(exist = false)
	var children: List<CompanyPermissionsView>? = null,

	@TableField(exist = false)
	var url:String ?= null
) {
	fun insertPermissionsAll(dto: CompanyPermissionsViewDto, companyId: Long?, userId: Long?) {
		permissionsId = dto.permissionsId
		permissionsName = dto.permissionsName!!
		sysPermParentId = dto.parentId
		orderNum = dto.orderNum
		visible = (dto.visible)
		icon = dto.icon
		createUserId = userId
		createTime = Date()
		updateUserId = userId
		updateTime = Date()
		createType = 1
		if (companyId != null) {
			this.companyId = companyId
		}
		permissionsType = dto.permissionsType
	}
}
